@cachly-dev/mcp-server 0.10.191 → 0.10.193

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,8 +24,9 @@ problem returns. Your Brain (the store of your lessons) lives on EU servers.
24
24
  /plugin install cachly-brain@cachly
25
25
  ```
26
26
 
27
- There is no JSON to write, no path to set and no key to copy. On the first tool call
28
- without a key, cachly creates a test Brain on EU servers. The test Brain has 14 days of
27
+ There is no JSON to write, no path to set and no key to copy. Without a key, cachly creates
28
+ a test Brain on EU servers when the session starts (the plugin hook does it; the first tool
29
+ call does it if the hook did not). The test Brain has 14 days of
29
30
  the Dev tier. After that it runs on the free tier with the same key.
30
31
 
31
32
  Check it with `claude mcp list`. You should see `plugin:cachly-brain:cachly … ✔ Connected`.
@@ -310,7 +311,7 @@ Manual snippets are in [Manual Setup](#manual-setup).
310
311
 
311
312
  | Editor / client | Auto-setup | Config file written | Global config | Notes |
312
313
  |---|---|---|---|---|
313
- | **Claude Code** | yes | `~/.claude/mcp.json` + `.mcp.json` | yes, always | Without a key: test Brain on the first tool call; browser sign-in only as fallback |
314
+ | **Claude Code** | yes | `~/.claude/mcp.json` + `.mcp.json` | yes, always | Without a key: test Brain at session start (plugin) or on the first tool call; browser sign-in only as fallback |
314
315
  | **Cursor** | yes, detected via `.cursor/` | `.cursor/mcp.json`, hooks in `.cursor/hooks.json` | no | Project-level; restart Cursor after setup. Lessons arrive with the first tool call of a turn |
315
316
  | **Windsurf** | yes, detected via `.windsurf/` | `.windsurf/mcp.json` | no | Project-level; restart Windsurf after setup |
316
317
  | **VS Code + Copilot** | yes, detected via `.vscode/` | `.vscode/mcp.json`, hooks in `.github/hooks/cachly-ambient.json` | no | Needs the VS Code MCP support or Copilot chat. Briefing at session start, lessons before each prompt |
@@ -1,2 +1,4 @@
1
- import{readFileSync as F}from"node:fs";import{parseHookPayload as _,runEinblendung as I,stopLernanfrage as T,stopObservation as E}from"./ambient-cli.js";import{stopAntwort as v}from"./schreibbeleg.js";import{holeBestand as C}from"./einblendung.js";import{belohnungMelden as x}from"./lernen.js";import{appendLedgerEntry as R,reportLedgerEntry as j}from"./ambient-ledger.js";import{copilotHatHook as N,cursorHatHook as G,findeInstanz as w,findeSchluessel as b,hookUmfeld as A,projektHatHook as z}from"./hook-zugang.js";import{CURSOR_FLAG as f,cursorEreignis as H,cursorHookAntwort as B,cursorLeer as D,istCursorNutzlast as P}from"./cursor-hook.js";import{COPILOT_FLAG as m,copilotEreignis as M,copilotHookAntwort as Y,istFremdeLaufzeit as L}from"./copilot-hook.js";import{CODEX_FLAG as U,codexHookAntwort as K}from"./codex-hook.js";import{GEMINI_FLAG as g,geminiEreignis as $,geminiHookAntwort as V}from"./gemini-hook.js";const J="https://api.cachly.dev",X="ambient-auffrischen",k=new Set(["SessionStart","UserPromptSubmit","PreToolUse","Stop"]);async function q(t,e){if(!t.args.includes(f)&&(H(e,t.args)!=="sessionStart"||G(t.umfeld)))return"";const s=t.args.filter(n=>n==="--plugin");return B({payload:e,args:t.args,claudeLauf:(n,c)=>S({...t,raw:n,args:[c,...s]}),ablageOrdner:t.cursorAblage})}function Q(t,e){const r=(s,n)=>S({...t,raw:s,args:[n]});return t.args.includes(m)?Y({payload:e,args:t.args,claudeLauf:r,ablageOrdner:t.copilotAblage}):t.args.includes(U)?K({payload:e,args:t.args,claudeLauf:r}):t.args.includes(g)?V({payload:e,args:t.args,claudeLauf:r}):null}function W(t,e){return t.includes(f)||P(e)?"cursor":t.includes(m)?"copilot":t.includes(U)?"codex":t.includes(g)?"gemini":L(e)?"vscode":"claude"}async function S(t){try{const e=_(t.raw),r={...t,editor:t.editor??W(t.args,e)};if(r.args.includes(f)||P(e))return await q(r,e);const s=Q(r,e);if(s)return await s;const n=e?.hook_event_name??r.args.find(i=>k.has(i))??r.umfeld.env.CACHLY_HOOK_EVENT??"";if(L(e)&&(n!=="SessionStart"&&n!=="UserPromptSubmit"||N(r.umfeld))||r.args.includes("--plugin")&&n&&z(n,r.umfeld))return"";let c=null;if(n==="Stop"&&e?.transcript_path)try{c=F(e.transcript_path,"utf-8").split(`
2
- `);const i=v(c,e.stop_hook_active===!0);if(i)return i}catch{}const a=b(r.umfeld),u=w(r.umfeld);if(!a||!u)return"";const o={apiUrl:r.apiUrl,jwt:a,instanceId:u};if(n==="Stop"){const i=e?E(e):null,d=i?(r.fetchFn??fetch)(`${o.apiUrl}/api/v1/instances/${o.instanceId}/learn`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.jwt}`},body:JSON.stringify(T(i)),signal:AbortSignal.timeout(8e3)}).catch(()=>{}):void 0,l=x(o,e?.session_id??null,c,{fetchFn:r.fetchFn});return await Promise.all([d,l]),""}let p;const y=await(r.einblenden??I)(r.raw,{cfg:o,nebenlauf:r.selbst?[r.selbst,X]:void 0,editor:r.editor,fetchFn:r.fetchFn,onInject:(i,d)=>{const l={ts:new Date().toISOString(),event:d,injected:i,prevented:0};R(l),p=j(o,l,r.fetchFn)}});return p&&await Promise.race([p,new Promise(i=>setTimeout(i,500))]),y}catch{return""}}async function Z(){if(process.stdin.isTTY)return"";const t=[];for await(const e of process.stdin)t.push(e);return Buffer.concat(t).toString("utf-8")}function O(){return process.env.CACHLY_API_URL||J}const h={SessionStart:25e3,UserPromptSubmit:8e3,PreToolUse:8e3,Stop:5e4,sessionStart:25e3,beforeSubmitPrompt:8e3,postToolUse:3e3,userPromptSubmitted:8e3,PostToolUse:3e3,BeforeAgent:8e3};function tt(t,e){return t.includes(f)?D(H(e,t)):t.includes(m)?M(e,t)?"{}":"":t.includes(g)&&$(e,t)?"{}":""}async function pt(t,e){try{const r=await Z(),s=_(r),n=s?.hook_event_name??t.find(o=>k.has(o)||Object.hasOwn(h,o))??"",c=Number(process.env.CACHLY_HOOK_FRIST_MS)||h[n]||h.UserPromptSubmit,a=tt(t,s),u=await Promise.race([S({args:t,raw:r,umfeld:A(),apiUrl:O(),selbst:e}),new Promise(o=>setTimeout(()=>o(a),c))]);u&&await new Promise(o=>process.stdout.write(u,()=>o()))}catch{}process.exit(0)}async function dt(){try{const t=A(),e=b(t),r=w(t);e&&r&&await C({apiUrl:O(),jwt:e,instanceId:r},{force:!0,lernen:!0})}catch{}process.exit(0)}export{X as AUFFRISCHEN,h as HOOK_FRIST_MS,J as STANDARD_API_URL,dt as auffrischenHauptlauf,W as editorVon,S as hookAntwort,pt as hookHauptlauf};
1
+ import{readFileSync as F}from"node:fs";import{parseHookPayload as k,runEinblendung as T,stopLernanfrage as v,stopObservation as C}from"./ambient-cli.js";import{stopAntwort as x}from"./schreibbeleg.js";import{holeBestand as K,hookAusgabe as z}from"./einblendung.js";import{belohnungMelden as N}from"./lernen.js";import{appendLedgerEntry as j,reportLedgerEntry as R}from"./ambient-ledger.js";import{copilotHatHook as M,cursorHatHook as G,findeInstanz as A,findeSchluessel as H,hookUmfeld as b,pluginVersion as B,projektHatHook as Y}from"./hook-zugang.js";import{ABKUEHLUNG_HOOK_MS as $,schreibeAuftrag as D,sichereKonto as J,startwissenEingeschaltet as V}from"./konto-anlegen.js";import{istInstanzKennung as Q,sofortTestHinweis as X}from"./zugang.js";import{CURSOR_FLAG as p,cursorEreignis as O,cursorHookAntwort as q,cursorLeer as W,istCursorNutzlast as y}from"./cursor-hook.js";import{COPILOT_FLAG as g,copilotEreignis as Z,copilotHookAntwort as tt,istFremdeLaufzeit as I}from"./copilot-hook.js";import{CODEX_FLAG as U,codexHookAntwort as et}from"./codex-hook.js";import{GEMINI_FLAG as h,geminiEreignis as nt,geminiHookAntwort as rt}from"./gemini-hook.js";const ot="https://api.cachly.dev",L=5e3,it="ambient-auffrischen",P=new Set(["SessionStart","UserPromptSubmit","PreToolUse","Stop"]);async function st(t,e){if(!t.args.includes(p)&&(O(e,t.args)!=="sessionStart"||G(t.umfeld)))return"";const i=t.args.filter(r=>r==="--plugin");return q({payload:e,args:t.args,claudeLauf:(r,u)=>S({...t,raw:r,args:[u,...i]}),ablageOrdner:t.cursorAblage})}function ct(t,e){const n=(i,r)=>S({...t,raw:i,args:[r]});return t.args.includes(g)?tt({payload:e,args:t.args,claudeLauf:n,ablageOrdner:t.copilotAblage}):t.args.includes(U)?et({payload:e,args:t.args,claudeLauf:n}):t.args.includes(h)?rt({payload:e,args:t.args,claudeLauf:n}):null}function ut(t,e){return t.includes(p)||y(e)?"cursor":t.includes(g)?"copilot":t.includes(U)?"codex":t.includes(h)?"gemini":I(e)?"vscode":"claude"}async function at(t){const e=await J({apiUrl:t.apiUrl,version:B(t.umfeld),home:t.umfeld.heim,env:{...t.umfeld.env,CACHLY_QUELLE:"claude-code-plugin"},fristMs:L,anfrageMs:L,abkuehlungMs:$,holen:t.fetchFn});return e.art==="vorhanden"?{apiKey:e.apiKey,instanzId:e.instanzId,hinweis:""}:e.art!=="angelegt"?null:(V(t.umfeld.env)&&D({instanzId:e.test.instanzId,projekt:t.umfeld.projekt},{home:t.umfeld.heim}),{apiKey:e.test.apiKey,instanzId:e.test.instanzId,hinweis:X(e.test)})}function ft(t,e){const n=e.replace(/^\s+/,"");if(!t)return z("SessionStart",n);try{const i=JSON.parse(t),r=i.hookSpecificOutput?.additionalContext;return!i.hookSpecificOutput||typeof r!="string"?t:(i.hookSpecificOutput.additionalContext=`${n}
2
+
3
+ ${r}`,JSON.stringify(i))}catch{return t}}async function S(t){try{const e=k(t.raw),n={...t,editor:t.editor??ut(t.args,e)};if(n.args.includes(p)||y(e))return await st(n,e);const i=ct(n,e);if(i)return await i;const r=e?.hook_event_name??n.args.find(o=>P.has(o))??n.umfeld.env.CACHLY_HOOK_EVENT??"";if(I(e)&&(r!=="SessionStart"&&r!=="UserPromptSubmit"||M(n.umfeld))||n.args.includes("--plugin")&&r&&Y(r,n.umfeld))return"";let u=null;if(r==="Stop"&&e?.transcript_path)try{u=F(e.transcript_path,"utf-8").split(`
4
+ `);const o=x(u,e.stop_hook_active===!0);if(o)return o}catch{}let a=H(n.umfeld),c=A(n.umfeld),s="";if(!a&&r==="SessionStart"&&n.args.includes("--plugin")&&!Q(c)){const o=await at(n);o&&(a=o.apiKey,c=o.instanzId??c,s=o.hinweis)}if(!a||!c)return"";const f={apiUrl:n.apiUrl,jwt:a,instanceId:c};if(r==="Stop"){const o=e?C(e):null,m=o?(n.fetchFn??fetch)(`${f.apiUrl}/api/v1/instances/${f.instanceId}/learn`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${f.jwt}`},body:JSON.stringify(v(o)),signal:AbortSignal.timeout(8e3)}).catch(()=>{}):void 0,l=N(f,e?.session_id??null,u,{fetchFn:n.fetchFn});return await Promise.all([m,l]),""}let d;const w=await(n.einblenden??T)(n.raw,{cfg:f,nebenlauf:n.selbst?[n.selbst,it]:void 0,editor:n.editor,fetchFn:n.fetchFn,onInject:(o,m)=>{const l={ts:new Date().toISOString(),event:m,injected:o,prevented:0};j(l),d=R(f,l,n.fetchFn)}});return d&&await Promise.race([d,new Promise(o=>setTimeout(o,500))]),s?ft(w,s):w}catch{return""}}async function lt(){if(process.stdin.isTTY)return"";const t=[];for await(const e of process.stdin)t.push(e);return Buffer.concat(t).toString("utf-8")}function E(){return process.env.CACHLY_API_URL||ot}const _={SessionStart:25e3,UserPromptSubmit:8e3,PreToolUse:8e3,Stop:5e4,sessionStart:25e3,beforeSubmitPrompt:8e3,postToolUse:3e3,userPromptSubmitted:8e3,PostToolUse:3e3,BeforeAgent:8e3};function pt(t,e){return t.includes(p)?W(O(e,t)):t.includes(g)?Z(e,t)?"{}":"":t.includes(h)&&nt(e,t)?"{}":""}async function It(t,e){try{const n=await lt(),i=k(n),r=i?.hook_event_name??t.find(s=>P.has(s)||Object.hasOwn(_,s))??"",u=Number(process.env.CACHLY_HOOK_FRIST_MS)||_[r]||_.UserPromptSubmit,a=pt(t,i),c=await Promise.race([S({args:t,raw:n,umfeld:b(),apiUrl:E(),selbst:e}),new Promise(s=>setTimeout(()=>s(a),u))]);c&&await new Promise(s=>process.stdout.write(c,()=>s()))}catch{}process.exit(0)}async function Ut(){try{const t=b(),e=H(t),n=A(t);e&&n&&await K({apiUrl:E(),jwt:e,instanceId:n},{force:!0,lernen:!0})}catch{}process.exit(0)}export{it as AUFFRISCHEN,_ as HOOK_FRIST_MS,L as KONTO_FRIST_MS,ot as STANDARD_API_URL,Ut as auffrischenHauptlauf,ut as editorVon,S as hookAntwort,It as hookHauptlauf};
@@ -1,8 +1,8 @@
1
- import{existsSync as C}from"node:fs";import{readFile as m,writeFile as s,chmod as c,mkdir as d}from"node:fs/promises";import{resolve as a}from"node:path";import{instanzIdFuerSkript as _,schluesselFuerSkript as L}from"./git-ohne-shell.js";const u="v2",S=/(?:#!\/bin\/sh\n)?# cachly CLS[\s\S]*?\nexit 0\n?/;async function y(n,t,p){if(!C(a(n,".git")))return"skipped-no-git";const l=a(n,".git","hooks"),e=a(l,"post-commit");await d(l,{recursive:!0});const i=f(t,p);let o="";try{o=await m(e,"utf-8")}catch{}if(!o)return await s(e,i+`
2
- `,"utf-8"),await c(e,493).catch(()=>{}),"written";if(o.includes(`cachly CLS \u2014 Continuous Learning Stream ${u}`))return"unchanged";if(S.test(o)){const r=o.replace(S,i);return await s(e,r.endsWith(`
3
- `)?r:r+`
4
- `,"utf-8"),await c(e,493).catch(()=>{}),"upgraded"}return await s(e,o.trimEnd()+`
1
+ import{existsSync as S}from"node:fs";import{readFile as m,writeFile as r,chmod as s,mkdir as d}from"node:fs/promises";import{resolve as a}from"node:path";import{instanzIdFuerSkript as C}from"./git-ohne-shell.js";const p="v3",u=/(?:#!\/bin\/sh\n)?# cachly CLS[\s\S]*?\nexit 0\n?/;async function A(e,c,h){if(!S(a(e,".git")))return"skipped-no-git";const l=a(e,".git","hooks"),t=a(l,"post-commit");await d(l,{recursive:!0});const n=L(c);let i="";try{i=await m(t,"utf-8")}catch{}if(!i)return await r(t,n+`
2
+ `,"utf-8"),await s(t,493).catch(()=>{}),"written";if(i.includes(`cachly CLS \u2014 Continuous Learning Stream ${p}`))return"unchanged";if(u.test(i)){const o=i.replace(u,n);return await r(t,o.endsWith(`
3
+ `)?o:o+`
4
+ `,"utf-8"),await s(t,493).catch(()=>{}),"upgraded"}return await r(t,i.trimEnd()+`
5
5
 
6
- `+i+`
7
- `,"utf-8"),await c(e,493).catch(()=>{}),"appended"}const h="try{var p={instance_id:process.env.CACHLY_BRAIN_INSTANCE_ID,source:'git_commit',payload:{message:process.env.CLS_MSG||'',sha:process.env.CLS_SHA||'',files:(process.env.CLS_FILES||'').split(',').filter(Boolean)}};require('child_process').execFileSync('npx',['@cachly-dev/mcp-server@latest','cls-ingest',JSON.stringify(p)],{stdio:'ignore',timeout:8000});}catch(e){}";function f(n,t){return n=_(n),t&&(t=L(t)),["#!/bin/sh",`# cachly CLS \u2014 Continuous Learning Stream ${u}`,"# Runs silently on every commit to keep your brain up to date.",`export CACHLY_BRAIN_INSTANCE_ID="${n}"`,...t?[`export CACHLY_JWT="${t}"`]:[],'CLS_SHA=$(git rev-parse HEAD 2>/dev/null || echo "")',"CLS_MSG=$(git log -1 --pretty=%B 2>/dev/null | head -1 | cut -c1-200)","CLS_FILES=$(git diff-tree --no-commit-id -r --name-only HEAD 2>/dev/null | tr '\\n' ',' | sed 's/,$//')","export CLS_SHA CLS_MSG CLS_FILES",`node -e "${h}" 2>/dev/null &`,"exit 0"].join(`
8
- `)}export{u as CLS_HOOK_VERSION,f as buildClsPostCommitHook,y as installClsPostCommitHook};
6
+ `+n+`
7
+ `,"utf-8"),await s(t,493).catch(()=>{}),"appended"}const _="try{var p={instance_id:process.env.CACHLY_BRAIN_INSTANCE_ID,source:'git_commit',payload:{message:process.env.CLS_MSG||'',sha:process.env.CLS_SHA||'',files:(process.env.CLS_FILES||'').split(',').filter(Boolean)}};require('child_process').execFileSync('npx',['@cachly-dev/mcp-server@latest','cls-ingest',JSON.stringify(p)],{stdio:'ignore',timeout:8000});}catch(e){}";function L(e,c){return e=C(e),["#!/bin/sh",`# cachly CLS \u2014 Continuous Learning Stream ${p}`,"# Runs silently on every commit to keep your brain up to date.",`export CACHLY_BRAIN_INSTANCE_ID="${e}"`,'CLS_SHA=$(git rev-parse HEAD 2>/dev/null || echo "")',"CLS_MSG=$(git log -1 --pretty=%B 2>/dev/null | head -1 | cut -c1-200)","CLS_FILES=$(git diff-tree --no-commit-id -r --name-only HEAD 2>/dev/null | tr '\\n' ',' | sed 's/,$//')","export CLS_SHA CLS_MSG CLS_FILES",`node -e "${_}" 2>/dev/null &`,"exit 0"].join(`
8
+ `)}export{p as CLS_HOOK_VERSION,L as buildClsPostCommitHook,A as installClsPostCommitHook};
@@ -1,8 +1,8 @@
1
- import{readFileSync as L,existsSync as M,writeFileSync as x,mkdirSync as K,statSync as q,appendFileSync as F}from"node:fs";import{dirname as C,join as S}from"node:path";import{tmpdir as k}from"node:os";import{createHash as G}from"node:crypto";import{spawn as W}from"node:child_process";import{Einblendbestand as T,torWoerter as R}from"./einblendung-kern.js";import{rahmeEin as j}from"./einblendung-rahmen.js";import{istMarkiert as V}from"./verdacht-marke.js";import{leserText as X}from"./seltenheitsbestand.js";import{mischeMitLeser as $}from"./leser.js";import{LeserSicherung as Q,dateiSpeicher as ee,frageLeser as te}from"./leser-sicherung.js";import{LESER_TIEFE_EINBLENDUNG as ne,LESER_ZEITLIMIT_MS as re}from"./rangfolge-stellschrauben.js";import{stufeEinblendungNachVersion as se}from"./gueltigkeit-version.js";import{ARME as B,BASIS_MIN_BELEGE as oe,MERKMAL_KANDIDATEN as ie,OHNE_LERNEN as le,entscheide as ae,leseArmZaehlung as ce,lernEinstellungen as ue,lernenAuffrischen as pe,merkeEntscheidung as he,neuerSatz as fe,sitzungsKennung as me,zugKennung as de}from"./lernen.js";export*from"./einblendung-kern.js";import{belohnungMelden as et,lernenAuffrischen as tt,lernEinstellungen as nt,ARME as rt}from"./lernen.js";const ge=600*1e3,z=8e3,Ee=60*1e3,H=120,U=ne,Se=1500,A=re,ke=S(k(),"cachly-ambient-netlog.jsonl");function Ze(e=process.cwd()){const t={apiUrl:process.env.CACHLY_API_URL||"https://api.cachly.dev",jwt:process.env.CACHLY_JWT||"",instanceId:process.env.CACHLY_BRAIN_INSTANCE_ID||""};if(t.jwt&&t.instanceId)return t;let n=e;for(let o=0;o<8;o++){const s=S(n,".mcp.json");if(M(s))try{const i=JSON.parse(L(s,"utf8"))?.mcpServers?.cachly?.env??{};if(t.apiUrl=t.apiUrl||i.CACHLY_API_URL||"https://api.cachly.dev",t.jwt=t.jwt||i.CACHLY_JWT||"",t.instanceId=t.instanceId||i.CACHLY_BRAIN_INSTANCE_ID||"",t.jwt&&t.instanceId)return t}catch{}const r=C(n);if(r===n)break;n=r}return t}function I(e){return G("sha1").update(e).digest("hex").slice(0,12)}function ye(e){return S(k(),`cachly-ambient-bestand-${I(e)}.json`)}function _e(e){return S(k(),`cachly-leser-sicherung-${I(e)}.json`)}function Ae(e){return S(k(),`cachly-ambient-auffrischen-${I(e)}.lock`)}async function O(e,{fetchFn:t=fetch,zeitlimitMs:n=z}={}){try{const o=await t(`${e.apiUrl}/api/v1/instances/${e.instanceId}/export`,{headers:{Authorization:`Bearer ${e.jwt}`},signal:AbortSignal.timeout(n)});if(!o.ok)return null;const s=await o.json();return Array.isArray(s?.lessons)?s.lessons.map(r=>typeof r=="string"?Ie(r):r).filter(r=>!!r&&typeof r=="object"):null}catch{return null}}function Ie(e){try{return JSON.parse(e)}catch{return null}}function P(e,t){try{K(C(e),{recursive:!0}),x(e,JSON.stringify({at:Date.now(),lessons:t}),{mode:384})}catch{}}function D(e){try{const t=JSON.parse(L(e,"utf8"));if(Array.isArray(t?.lessons))return{at:Number(t.at)||0,lessons:t.lessons}}catch{}return null}function be(e,t){const n=Ae(e.instanceId);try{if(M(n)&&Date.now()-q(n).mtimeMs<Ee)return;x(n,String(Date.now()),{mode:384})}catch{return}try{W(process.execPath,t,{detached:!0,stdio:"ignore",env:{...process.env,CACHLY_API_URL:e.apiUrl,CACHLY_JWT:e.jwt,CACHLY_BRAIN_INSTANCE_ID:e.instanceId}}).unref()}catch{}}async function we(e,{force:t=!1,nebenlauf:n,abrufMs:o=z,lernen:s=!1,fetchFn:r}={}){if(!e.jwt||!e.instanceId)return{lessons:[],quelle:"nicht-eingerichtet"};const i=ye(e.instanceId);if(t){const[l]=await Promise.all([O(e,{fetchFn:r,zeitlimitMs:o}),s?pe(e,{fetchFn:r}):void 0]);if(l)return P(i,l),{lessons:l,quelle:"server"};const m=D(i);return m?{lessons:m.lessons,quelle:"platte-alt"}:{lessons:[],quelle:"server-nicht-erreichbar"}}const p=D(i);if(p){const l=Date.now()-p.at<ge;return!l&&n&&be(e,n),{lessons:p.lessons,quelle:l?"platte":"platte-alt"}}const c=await O(e,{fetchFn:r,zeitlimitMs:o});return c?(P(i,c),{lessons:c,quelle:"server"}):{lessons:[],quelle:"server-nicht-erreichbar"}}function b(e){return Math.ceil(String(e).length/4)}function w(e){const t=e.severity?`[${e.severity}] `:"",n=String(e.what_worked??"").replace(/\s+/g," ").trim(),o=n.length>H?`${n.slice(0,H)}\u2026`:n,s=typeof e.versionshinweis=="string"?` [${e.versionshinweis}]`:"";return`- ${t}${e.topic}${s}: ${o}`}const y={lessons:[],tokens:0,topScore:0,belege:0};function N(e,t,n){if(e.length===0)return{...y};const o=[];let s=0;e=se(e);for(const{lektion:r}of e.slice(0,t)){const i=b(w(r));if(s+i>n)break;o.push(r),s+=i}return{lessons:o,tokens:s,topScore:Math.round(e[0].punkte*100)/100,belege:e[0].belege}}function Je(e,t,{minBelege:n=2,topK:o=3,tokenBudget:s=600}={}){if(!Array.isArray(t)||t.length===0)return{...y};if(R(e).length===0)return{...y};const r=new T(t).sortiere(e).filter(i=>i.belege>=n);return r.length===0?{...y}:N(r,o,s)}function Ne(e){return X(e,Se)}async function Y(e,t,n,{zeitlimitMs:o=A,fetchFn:s}={}){if(!e?.jwt||!e?.instanceId||n.length===0)return{art:"ohne"};if(["0","off","aus","false"].includes(String(process.env.CACHLY_LESER||"").toLowerCase()))return{art:"ohne"};const r=new Q(ee(_e(e.instanceId)));return te({url:`${e.apiUrl}/api/v1/rerank`,jwt:e.jwt,frage:t,texte:n,instanceId:e.instanceId,zeitlimitMs:o,fetchFn:s},r)}async function Ke(e,t,n,o={}){const s=await Y(e,t,n,o);return s.art==="punkte"?{scores:s.scores,provider:s.provider,ms:s.ms}:null}async function Z(e,t,n,{minBelege:o,tiefe:s,zeitlimitMs:r,fetchFn:i}){const p={sortiert:[],leser:"aus",leserMs:0};if(!Array.isArray(t)||t.length===0||R(e).length===0)return p;let c=new T(t).sortiere(e).filter(h=>h.belege>=o);if(c.length===0)return p;let l="aus",m=0;if(c.length>1&&s>0){const h=c.slice(0,s),g=c.slice(s),f=await Y(n,e,h.map(E=>Ne(E.lektion)),{zeitlimitMs:r,fetchFn:i});f.art==="punkte"?(c=[...$(h.map(u=>u.punkte),f.scores,1).map(u=>({...h[u],leser:f.scores[u]})),...g],l=f.provider,m=f.ms):f.art==="uebersprungen"&&(l="uebersprungen")}return{sortiert:c,leser:l,leserMs:m}}async function qe(e,t,n,{minBelege:o=2,topK:s=3,tokenBudget:r=600,tiefe:i=U,zeitlimitMs:p=A,fetchFn:c}={}){const l=await Z(e,t,n,{minBelege:o,tiefe:i,zeitlimitMs:p,fetchFn:c});return{...N(l.sortiert,s,r),leser:l.leser,leserMs:l.leserMs}}function ve(e){if(!e.lessons.length)return"";const t=e.lessons.map(w).join(`
1
+ import{readFileSync as T,existsSync as C,writeFileSync as R,mkdirSync as Y,statSync as Z,appendFileSync as G}from"node:fs";import{dirname as j,join as _}from"node:path";import{tmpdir as S}from"node:os";import{createHash as F}from"node:crypto";import{spawn as W}from"node:child_process";import{Einblendbestand as $,torWoerter as B}from"./einblendung-kern.js";import{rahmeEin as U}from"./einblendung-rahmen.js";import{istMarkiert as V}from"./verdacht-marke.js";import{leserText as X}from"./seltenheitsbestand.js";import{mischeMitLeser as z}from"./leser.js";import{LeserSicherung as Q,dateiSpeicher as ee,frageLeser as te}from"./leser-sicherung.js";import{LESER_TIEFE_EINBLENDUNG as ne,LESER_ZEITLIMIT_MS as re}from"./rangfolge-stellschrauben.js";import{stufeEinblendungNachVersion as se}from"./gueltigkeit-version.js";import{ARME as H,BASIS_MIN_BELEGE as oe,MERKMAL_KANDIDATEN as ie,OHNE_LERNEN as le,entscheide as ae,leseArmZaehlung as ce,lernEinstellungen as ue,lernenAuffrischen as pe,merkeEntscheidung as fe,neuerSatz as he,sitzungsKennung as me,zugKennung as de}from"./lernen.js";export*from"./einblendung-kern.js";import{belohnungMelden as it,lernenAuffrischen as lt,lernEinstellungen as at,ARME as ct}from"./lernen.js";const ge=600*1e3,Ee=300*1e3,_e=10*1e3,Se=2e3,Ae=50,ke=60*1e3;function Ie(e,t){return t<Ee?{ttlMs:_e,sofort:!0}:e<Ae?{ttlMs:ke,sofort:!1}:{ttlMs:ge,sofort:!1}}const O=8e3,Ne=60*1e3,P=120,D=ne,ye=1500,I=re,be=_(S(),"cachly-ambient-netlog.jsonl");function We(e=process.cwd()){const t={apiUrl:process.env.CACHLY_API_URL||"https://api.cachly.dev",jwt:process.env.CACHLY_JWT||"",instanceId:process.env.CACHLY_BRAIN_INSTANCE_ID||""};if(t.jwt&&t.instanceId)return t;let n=e;for(let s=0;s<8;s++){const o=_(n,".mcp.json");if(C(o))try{const i=JSON.parse(T(o,"utf8"))?.mcpServers?.cachly?.env??{};if(t.apiUrl=t.apiUrl||i.CACHLY_API_URL||"https://api.cachly.dev",t.jwt=t.jwt||i.CACHLY_JWT||"",t.instanceId=t.instanceId||i.CACHLY_BRAIN_INSTANCE_ID||"",t.jwt&&t.instanceId)return t}catch{}const r=j(n);if(r===n)break;n=r}return t}function N(e){return F("sha1").update(e).digest("hex").slice(0,12)}function we(e){return _(S(),`cachly-ambient-bestand-${N(e)}.json`)}function Me(e){return _(S(),`cachly-leser-sicherung-${N(e)}.json`)}function Le(e){return _(S(),`cachly-ambient-auffrischen-${N(e)}.lock`)}async function y(e,{fetchFn:t=fetch,zeitlimitMs:n=O}={}){try{const s=await t(`${e.apiUrl}/api/v1/instances/${e.instanceId}/export`,{headers:{Authorization:`Bearer ${e.jwt}`},signal:AbortSignal.timeout(n)});if(!s.ok)return null;const o=await s.json();return Array.isArray(o?.lessons)?o.lessons.map(r=>typeof r=="string"?ve(r):r).filter(r=>!!r&&typeof r=="object"):null}catch{return null}}function ve(e){try{return JSON.parse(e)}catch{return null}}function b(e,t){try{const n=Date.now(),s=w(e)?.seit??n;Y(j(e),{recursive:!0}),R(e,JSON.stringify({at:n,seit:s,lessons:t}),{mode:384})}catch{}}function w(e){try{const t=JSON.parse(T(e,"utf8"));if(Array.isArray(t?.lessons)){const n=Number(t.at)||0;return{at:n,seit:Number(t.seit)||n,lessons:t.lessons}}}catch{}return null}function xe(e,t){const n=Le(e.instanceId);try{if(C(n)&&Date.now()-Z(n).mtimeMs<Ne)return;R(n,String(Date.now()),{mode:384})}catch{return}try{W(process.execPath,t,{detached:!0,stdio:"ignore",env:{...process.env,CACHLY_API_URL:e.apiUrl,CACHLY_JWT:e.jwt,CACHLY_BRAIN_INSTANCE_ID:e.instanceId}}).unref()}catch{}}async function Te(e,{force:t=!1,nebenlauf:n,abrufMs:s=O,lernen:o=!1,fetchFn:r}={}){if(!e.jwt||!e.instanceId)return{lessons:[],quelle:"nicht-eingerichtet"};const i=we(e.instanceId);if(t){const[a]=await Promise.all([y(e,{fetchFn:r,zeitlimitMs:s}),o?pe(e,{fetchFn:r}):void 0]);if(a)return b(i,a),{lessons:a,quelle:"server"};const f=w(i);return f?{lessons:f.lessons,quelle:"platte-alt"}:{lessons:[],quelle:"server-nicht-erreichbar"}}const l=w(i);if(l){const a=Date.now(),f=Ie(l.lessons.length,a-l.seit);if(a-l.at<f.ttlMs)return{lessons:l.lessons,quelle:"platte"};if(f.sofort){const m=await y(e,{fetchFn:r,zeitlimitMs:Math.min(s,Se)});return m?(b(i,m),{lessons:m,quelle:"server"}):{lessons:l.lessons,quelle:"platte-alt"}}return n&&xe(e,n),{lessons:l.lessons,quelle:"platte-alt"}}const u=await y(e,{fetchFn:r,zeitlimitMs:s});return u?(b(i,u),{lessons:u,quelle:"server"}):{lessons:[],quelle:"server-nicht-erreichbar"}}function M(e){return Math.ceil(String(e).length/4)}function L(e){const t=e.severity?`[${e.severity}] `:"",n=String(e.what_worked??"").replace(/\s+/g," ").trim(),s=n.length>P?`${n.slice(0,P)}\u2026`:n,o=typeof e.versionshinweis=="string"?` [${e.versionshinweis}]`:"";return`- ${t}${e.topic}${o}: ${s}`}const A={lessons:[],tokens:0,topScore:0,belege:0};function v(e,t,n){if(e.length===0)return{...A};const s=[];let o=0;e=se(e);for(const{lektion:r}of e.slice(0,t)){const i=M(L(r));if(o+i>n)break;s.push(r),o+=i}return{lessons:s,tokens:o,topScore:Math.round(e[0].punkte*100)/100,belege:e[0].belege}}function Ve(e,t,{minBelege:n=2,topK:s=3,tokenBudget:o=600}={}){if(!Array.isArray(t)||t.length===0)return{...A};if(B(e).length===0)return{...A};const r=new $(t).sortiere(e).filter(i=>i.belege>=n);return r.length===0?{...A}:v(r,s,o)}function Ce(e){return X(e,ye)}async function J(e,t,n,{zeitlimitMs:s=I,fetchFn:o}={}){if(!e?.jwt||!e?.instanceId||n.length===0)return{art:"ohne"};if(["0","off","aus","false"].includes(String(process.env.CACHLY_LESER||"").toLowerCase()))return{art:"ohne"};const r=new Q(ee(Me(e.instanceId)));return te({url:`${e.apiUrl}/api/v1/rerank`,jwt:e.jwt,frage:t,texte:n,instanceId:e.instanceId,zeitlimitMs:s,fetchFn:o},r)}async function Xe(e,t,n,s={}){const o=await J(e,t,n,s);return o.art==="punkte"?{scores:o.scores,provider:o.provider,ms:o.ms}:null}async function K(e,t,n,{minBelege:s,tiefe:o,zeitlimitMs:r,fetchFn:i}){const l={sortiert:[],leser:"aus",leserMs:0};if(!Array.isArray(t)||t.length===0||B(e).length===0)return l;let u=new $(t).sortiere(e).filter(h=>h.belege>=s);if(u.length===0)return l;let a="aus",f=0;if(u.length>1&&o>0){const h=u.slice(0,o),m=u.slice(o),d=await J(n,e,h.map(E=>Ce(E.lektion)),{zeitlimitMs:r,fetchFn:i});d.art==="punkte"?(u=[...z(h.map(p=>p.punkte),d.scores,1).map(p=>({...h[p],leser:d.scores[p]})),...m],a=d.provider,f=d.ms):d.art==="uebersprungen"&&(a="uebersprungen")}return{sortiert:u,leser:a,leserMs:f}}async function Qe(e,t,n,{minBelege:s=2,topK:o=3,tokenBudget:r=600,tiefe:i=D,zeitlimitMs:l=I,fetchFn:u}={}){const a=await K(e,t,n,{minBelege:s,tiefe:i,zeitlimitMs:l,fetchFn:u});return{...v(a.sortiert,o,r),leser:a.leser,leserMs:a.leserMs}}function Re(e){if(!e.lessons.length)return"";const t=e.lessons.map(L).join(`
2
2
  `);return`\u{1F9E0} Cachly Brain \u2014 relevant lessons for this task (auto-recall, ${e.lessons.length}):
3
- ${j(t)}
4
- (ambient-recall \xB7 ~${e.tokens} tokens \xB7 match score ${e.topScore})`}const Le=5;function Fe(e){const t=e.filter(r=>!V(r));if(!t.length)return"";const n=t.filter(r=>{const i=String(r.topic??"");return!(/^auto:/.test(i)||/^[a-z]+:?$/.test(i))}),s=[...n.length?n:t].sort((r,i)=>(Number(i.recall_count)||0)-(Number(r.recall_count)||0)).slice(0,Le).map(w).join(`
3
+ ${U(t)}
4
+ (ambient-recall \xB7 ~${e.tokens} tokens \xB7 match score ${e.topScore})`}const je=5;function et(e){const t=e.filter(r=>!V(r));if(!t.length)return"";const n=t.filter(r=>{const i=String(r.topic??"");return!(/^auto:/.test(i)||/^[a-z]+:?$/.test(i))}),o=[...n.length?n:t].sort((r,i)=>(Number(i.recall_count)||0)-(Number(r.recall_count)||0)).slice(0,je).map(L).join(`
5
5
  `);return`\u{1F9E0} Cachly Brain \u2014 ambient recall active (${t.length} lessons). Top by proven reuse:
6
- ${j(s)}
7
- (Relevant lessons for each task are auto-injected per prompt. ~${b(s)} tokens.)`}function Ge(e,t){return t?JSON.stringify({hookSpecificOutput:{hookEventName:e,additionalContext:t}}):""}function Me(e,t){return e.map((n,o)=>({x:n,rang:o,gezeigt:t.includes(n.lektion)})).filter(({rang:n,gezeigt:o})=>n<ie||o).map(({x:n,rang:o,gezeigt:s})=>({thema:String(n.lektion.topic??""),rang:o,punkte:Math.round(n.punkte*1e3)/1e3,belege:n.belege,leser:typeof n.leser=="number"&&Number.isFinite(n.leser)?Math.round(n.leser*1e3)/1e3:null,gezeigt:s}))}async function We(e,t,{nebenlauf:n,abrufMs:o,leser:s=!0,session:r=null,protokoll:i=!0,ereignis:p="UserPromptSubmit",editor:c="",lernen:l=!0,fetchFn:m}={}){const{lessons:h,quelle:g}=await we(t,{nebenlauf:n,abrufMs:o,fetchFn:m}),f=ue(),E=l&&f.aktiv&&p==="UserPromptSubmit"&&!!t.instanceId,u=E?ae({instanceId:t.instanceId,sitzung:r,prompt:e,zaehlung:ce(t.instanceId),einstellungen:f}):le,v=B[u.arm]??B[0],d=await Z(e,h,t,{minBelege:oe,tiefe:s?U:0,zeitlimitMs:A,fetchFn:m}),a={...N(d.sortiert.filter(J=>J.belege>=v.minBelege),v.topK,600),leser:d.leser,leserMs:d.leserMs},_=u.kontrolle?"":ve(a);if(E&&d.sortiert.length>0&&he(t.instanceId,r,fe({sitzung:me(r),zug:de(e),ereignis:p,editor:c,arm:u.arm,kontrolle:u.kontrolle,erkundet:u.erkundet,ausgewaehlt:a.lessons.length,kandidatenZahl:d.sortiert.length,belege:a.belege,topScore:a.topScore,leser:a.leser,leserMs:a.leserMs,quelle:g,bestand:h.length,kandidaten:Me(d.sortiert,a.lessons)})),i)try{F(ke,JSON.stringify({at:Date.now(),session:r,prompt_tokens:b(e),injected_tokens:_?a.tokens:0,matches:_?a.lessons.length:0,arm:u.arm,kontrolle:u.kontrolle,ausgewaehlt:a.lessons.length,top_score:a.topScore,belege:a.belege,leser:a.leser,leser_ms:a.leserMs,quelle:g,bestand:h.length})+`
8
- `)}catch{}return{kontext:_,auswahl:a,quelle:g,bestand:h.length,entscheidung:u}}export{z as ABRUF_TIMEOUT_MS,H as ANZEIGE_ZEICHEN,rt as ARME,ge as BESTAND_TTL_MS,A as LESER_HOOK_ZEITLIMIT_MS,Se as LESER_MAX_ZEICHEN,U as LESER_TIEFE,ke as NETZ_PROTOKOLL,Le as SITZUNG_TOP_N,et as belohnungMelden,ye as bestandPfad,b as estimateTokens,we as holeBestand,Ge as hookAusgabe,nt as lernEinstellungen,tt as lernenAuffrischen,Y as leserAnfrageApi,Ke as leserPunkteApi,Ne as leserText,$ as mischeMitLeser,We as promptEinblendung,ve as promptKontext,w as renderLesson,Ze as resolveConfig,Je as selectRelevant,qe as selectRelevantMitLeser,_e as sicherungsPfad,Fe as sitzungsKontext,be as starteNebenlauf};
6
+ ${U(o)}
7
+ (Relevant lessons for each task are auto-injected per prompt. ~${M(o)} tokens.)`}function tt(e,t){return t?JSON.stringify({hookSpecificOutput:{hookEventName:e,additionalContext:t}}):""}function $e(e,t){return e.map((n,s)=>({x:n,rang:s,gezeigt:t.includes(n.lektion)})).filter(({rang:n,gezeigt:s})=>n<ie||s).map(({x:n,rang:s,gezeigt:o})=>({thema:String(n.lektion.topic??""),rang:s,punkte:Math.round(n.punkte*1e3)/1e3,belege:n.belege,leser:typeof n.leser=="number"&&Number.isFinite(n.leser)?Math.round(n.leser*1e3)/1e3:null,gezeigt:o}))}async function nt(e,t,{nebenlauf:n,abrufMs:s,leser:o=!0,session:r=null,protokoll:i=!0,ereignis:l="UserPromptSubmit",editor:u="",lernen:a=!0,fetchFn:f}={}){const{lessons:h,quelle:m}=await Te(t,{nebenlauf:n,abrufMs:s,fetchFn:f}),d=ue(),E=a&&d.aktiv&&l==="UserPromptSubmit"&&!!t.instanceId,p=E?ae({instanceId:t.instanceId,sitzung:r,prompt:e,zaehlung:ce(t.instanceId),einstellungen:d}):le,x=H[p.arm]??H[0],g=await K(e,h,t,{minBelege:oe,tiefe:o?D:0,zeitlimitMs:I,fetchFn:f}),c={...v(g.sortiert.filter(q=>q.belege>=x.minBelege),x.topK,600),leser:g.leser,leserMs:g.leserMs},k=p.kontrolle?"":Re(c);if(E&&g.sortiert.length>0&&fe(t.instanceId,r,he({sitzung:me(r),zug:de(e),ereignis:l,editor:u,arm:p.arm,kontrolle:p.kontrolle,erkundet:p.erkundet,ausgewaehlt:c.lessons.length,kandidatenZahl:g.sortiert.length,belege:c.belege,topScore:c.topScore,leser:c.leser,leserMs:c.leserMs,quelle:m,bestand:h.length,kandidaten:$e(g.sortiert,c.lessons)})),i)try{G(be,JSON.stringify({at:Date.now(),session:r,prompt_tokens:M(e),injected_tokens:k?c.tokens:0,matches:k?c.lessons.length:0,arm:p.arm,kontrolle:p.kontrolle,ausgewaehlt:c.lessons.length,top_score:c.topScore,belege:c.belege,leser:c.leser,leser_ms:c.leserMs,quelle:m,bestand:h.length})+`
8
+ `)}catch{}return{kontext:k,auswahl:c,quelle:m,bestand:h.length,entscheidung:p}}export{O as ABRUF_TIMEOUT_MS,P as ANZEIGE_ZEICHEN,ct as ARME,_e as BESTAND_TTL_JUNG_MS,ke as BESTAND_TTL_KLEIN_MS,ge as BESTAND_TTL_MS,Se as JUNG_ABRUF_MS,Ee as JUNG_FENSTER_MS,Ae as KLEIN_LEKTIONEN,I as LESER_HOOK_ZEITLIMIT_MS,ye as LESER_MAX_ZEICHEN,D as LESER_TIEFE,be as NETZ_PROTOKOLL,je as SITZUNG_TOP_N,it as belohnungMelden,Ie as bestandFrist,we as bestandPfad,M as estimateTokens,Te as holeBestand,tt as hookAusgabe,at as lernEinstellungen,lt as lernenAuffrischen,J as leserAnfrageApi,Xe as leserPunkteApi,Ce as leserText,z as mischeMitLeser,nt as promptEinblendung,Re as promptKontext,L as renderLesson,We as resolveConfig,Ve as selectRelevant,Qe as selectRelevantMitLeser,Me as sicherungsPfad,et as sitzungsKontext,xe as starteNebenlauf};
@@ -1 +1 @@
1
- import{readdirSync as u,readFileSync as f}from"node:fs";import{homedir as l}from"node:os";import{join as n}from"node:path";import{readInstanceId as j,resolveApiKey as k}from"./credentials.js";import{echterWert as d}from"./zugang.js";function E(o=process.env){return{env:o,heim:o.HOME||o.USERPROFILE||l(),projekt:o.CLAUDE_PROJECT_DIR||process.cwd()}}function i(o){try{return JSON.parse(f(o,"utf8"))}catch{return null}}function a(o){return[n(o.heim,".claude","mcp.json"),n(o.projekt,".mcp.json"),n(o.heim,".cursor","mcp.json"),n(o.heim,".codeium","windsurf","mcp_config.json")].map(e=>{const r=i(e)?.mcpServers?.cachly?.env;return r&&typeof r=="object"?r:{}})}function h(...o){for(const e of o){const r=d(e);if(r)return r}return""}function H(o){return h(o.env.CLAUDE_PLUGIN_OPTION_API_KEY,k({env:o.env,home:o.heim,cwd:o.projekt}),...a(o).map(e=>e.CACHLY_JWT))}function N(o){return h(o.env.CLAUDE_PLUGIN_OPTION_INSTANCE_ID,o.env.CACHLY_BRAIN_INSTANCE_ID,j({home:o.heim}),...a(o).map(e=>e.CACHLY_BRAIN_INSTANCE_ID))}const m="cachly-ambient-";function S(o){return[n(o.projekt,".cursor","hooks.json"),n(o.heim,".cursor","hooks.json")].some(e=>{const r=i(e)?.hooks;return!!r&&typeof r=="object"&&Object.values(r).some(t=>Array.isArray(t)&&t.some(s=>String(s?.command??"").includes(m)))})}function A(o){const e=o;return[e?.command,e?.bash,e?.powershell].some(r=>String(r??"").includes(m))}function g(o){const e=o.env.COPILOT_HOME?n(o.env.COPILOT_HOME,"hooks"):n(o.heim,".copilot","hooks");return[n(o.projekt,".github","hooks"),e].some(r=>{let t;try{t=u(r).filter(s=>s.endsWith(".json"))}catch{return!1}return t.some(s=>{const c=i(n(r,s))?.hooks;return!!c&&typeof c=="object"&&Object.values(c).some(p=>Array.isArray(p)&&p.some(A))})})}function v(o,e){return[n(e.projekt,".claude","settings.json"),n(e.projekt,".claude","settings.local.json"),n(e.heim,".claude","settings.json")].some(r=>{const t=i(r)?.hooks?.[o];return Array.isArray(t)&&t.some(s=>Array.isArray(s?.hooks)&&s.hooks.some(c=>String(c?.command??"").includes(m)))})}export{m as PROJEKT_HOOK_MARKE,g as copilotHatHook,S as cursorHatHook,N as findeInstanz,H as findeSchluessel,E as hookUmfeld,A as istCachlyEintrag,v as projektHatHook};
1
+ import{readdirSync as f,readFileSync as l}from"node:fs";import{homedir as k}from"node:os";import{join as n}from"node:path";import{readInstanceId as d,resolveApiKey as j}from"./credentials.js";import{echterWert as a}from"./zugang.js";function E(o=process.env){return{env:o,heim:o.HOME||o.USERPROFILE||k(),projekt:o.CLAUDE_PROJECT_DIR||process.cwd()}}function i(o){try{return JSON.parse(l(o,"utf8"))}catch{return null}}function u(o){return[n(o.heim,".claude","mcp.json"),n(o.projekt,".mcp.json"),n(o.heim,".cursor","mcp.json"),n(o.heim,".codeium","windsurf","mcp_config.json")].map(e=>{const r=i(e)?.mcpServers?.cachly?.env;return r&&typeof r=="object"?r:{}})}function h(...o){for(const e of o){const r=a(e);if(r)return r}return""}function g(o){return h(o.env.CLAUDE_PLUGIN_OPTION_API_KEY,j({env:o.env,home:o.heim,cwd:o.projekt}),...u(o).map(e=>e.CACHLY_JWT))}function v(o){return h(o.env.CLAUDE_PLUGIN_OPTION_INSTANCE_ID,o.env.CACHLY_BRAIN_INSTANCE_ID,d({home:o.heim}),...u(o).map(e=>e.CACHLY_BRAIN_INSTANCE_ID))}function N(o){const e=a(o.env.CLAUDE_PLUGIN_ROOT);if(!e)return"unbekannt";const r=i(n(e,".claude-plugin","plugin.json"))?.version;return typeof r=="string"&&/^\d[0-9A-Za-z.+-]{0,30}$/.test(r)?r:"unbekannt"}const m="cachly-ambient-";function H(o){return[n(o.projekt,".cursor","hooks.json"),n(o.heim,".cursor","hooks.json")].some(e=>{const r=i(e)?.hooks;return!!r&&typeof r=="object"&&Object.values(r).some(t=>Array.isArray(t)&&t.some(s=>String(s?.command??"").includes(m)))})}function A(o){const e=o;return[e?.command,e?.bash,e?.powershell].some(r=>String(r??"").includes(m))}function L(o){const e=o.env.COPILOT_HOME?n(o.env.COPILOT_HOME,"hooks"):n(o.heim,".copilot","hooks");return[n(o.projekt,".github","hooks"),e].some(r=>{let t;try{t=f(r).filter(s=>s.endsWith(".json"))}catch{return!1}return t.some(s=>{const c=i(n(r,s))?.hooks;return!!c&&typeof c=="object"&&Object.values(c).some(p=>Array.isArray(p)&&p.some(A))})})}function S(o,e){return[n(e.projekt,".claude","settings.json"),n(e.projekt,".claude","settings.local.json"),n(e.heim,".claude","settings.json")].some(r=>{const t=i(r)?.hooks?.[o];return Array.isArray(t)&&t.some(s=>Array.isArray(s?.hooks)&&s.hooks.some(c=>String(c?.command??"").includes(m)))})}export{m as PROJEKT_HOOK_MARKE,L as copilotHatHook,H as cursorHatHook,v as findeInstanz,g as findeSchluessel,E as hookUmfeld,A as istCachlyEintrag,N as pluginVersion,S as projektHatHook};